package com.ruoyi.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.repository.configuration.RedisRepositoriesRegistrar;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName SaTokenConfigure
 * @Description
 * @Author huangshun
 * @Date 2021/12/16 19:25
 */
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        System.out.println("file"+filepath);
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaRouteInterceptor())
                .addPathPatterns(
                        "/memberSku/collectedList",
                        "/business/addShopCart",
                        "/shop/follow",
                        "/shop/isFollowed",
                        "/order/createOrder",
                        "pay/**"
                )
                .excludePathPatterns("/*/**","/member/doLogin", "/member/doPhoneLogin", "/member/getPhoneCode", "/verifycode/getimage/**", "/user/register", "/business/**", "/weixin/**", "/shop/**", "/mainHome/**",
                        "/business/search", "/business/getSkuInfo", "/shop/getInfo", "/shop/getSkuList", "/profile/**",
                        "/shop/getNoticeList", "/order/payNotify", "/user/image", "/business/getShopCart", "/static/**", "/business/getShopCart","/common/upload",
                        "/business/getClassIdBySkuInfo", "/business/getChildData");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/image/**", "/profile/**").addResourceLocations("file:" + AppConfig.getProfile() + "/");
    }
}
